package com.app.bimo.commonbusiness.base;

import android.app.Application;
import android.util.Log;

import com.alibaba.android.arouter.launcher.ARouter;
import com.app.bimo.commonbusiness.BuildConfig;
import com.app.bimo.commonbusiness.network.RetrofitServiceManager;
import com.app.bimo.commonbusiness.util.Constant;
import com.app.bimo.commonbusiness.util.DataUtil;
import com.app.bimo.commonbusiness.util.SharedPreUtils;
import com.app.bimo.commonbusiness.util.SystemUtil;

import timber.log.Timber;

/**
 * Created by goldze on 2018/6/21 0021.
 * 基础库自身初始化操作
 */

public class BaseModuleInit implements IModuleInit {
    @Override
    public boolean onInitAhead(Application application) {
        //开启打印日志
        //初始化阿里路由框架
        if (BuildConfig.DEBUG) {
            Timber.plant(new Timber.DebugTree());
            ARouter.openLog();     // 打印日志
            ARouter.openDebug();   // 开启调试模式(如果在InstantRun模式下运行，必须开启调试模式！线上版本需要关闭,否则有安全风险)
        }
        ARouter.init(application); // 尽可能早，推荐在Application中初始化
        Timber.e("基础层初始化 -- onInitAhead");
        return false;
    }

    @Override
    public boolean onInitLow(Application application) {
        Timber.e("基 础层初始化 -- onInitLow");
        RetrofitServiceManager.getInstance().addAllHead(Constant.HttpPhoneMEI, SystemUtil.getIMEI(application.getApplicationContext()));
        RetrofitServiceManager.getInstance().addAllHead(Constant.HttpPhoneBrand, SystemUtil.getPhoneBrand());
        RetrofitServiceManager.getInstance().addAllHead(Constant.HttpAppVer, SystemUtil.getVerName(application.getApplicationContext()));
//        RetrofitServiceManager.getInstance().addAllHead(Constant.HttpAppVer, "1.1.1");
        RetrofitServiceManager.getInstance().addAllHead(Constant.HttpPhoneSource, "android");
        String token = SharedPreUtils.getInstance(application.getApplicationContext()).getString(Constant.HttpToken);
        if (!DataUtil.isEmpty(token)) {
            RetrofitServiceManager.getInstance().addAllHead(Constant.HttpToken, token);
        }
        Log.i("headers",SystemUtil.getIMEI(application.getApplicationContext())+"           "+SystemUtil.getPhoneBrand()+"          "+SystemUtil.getVerName(application.getApplicationContext())
                +"                      "+ token);

        return false;
    }
}
